#!/opt/lampp/bin/perl -w
use strict;
use warnings;
use DBI;

my $db_conn = DBI->connect("DBI:mysql:database=phone_num_search;host=127.0.0.1", 'root', 'tiku123qweasdzxc');
$db_conn->do('set names utf8');
open IN, 'data/area';
my %cities;
while (<IN>) {
	next if (length() < 5);
	chop;
	my @arr = split('	');
	$cities{$arr[1]} = $arr[2];
	my $sql = "update prefix set tag = $arr[2] where city = '$arr[1]'";
	$db_conn->do($sql);
}
close IN;
exit;

my $sql = "select prefix, city from prefix";
my $request = $db_conn->prepare($sql);
my $result = $request->execute();
while (my ($prefix, $city) = $request->fetchrow_array) {
	if (defined($cities{$city})) {
		$sql = "update prefix set tag = $cities{$city} where prefix = '$prefix'";
		$db_conn->do($sql);
	}
}
